package com.augurit.wf.bi.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augurit.wf.bi.web.form.WfViewConfigForm;
import com.augurit.wf.common.entity.WfViewConfig;

public class WfViewConfigConvertor {
	public static WfViewConfigForm convertVoToForm(WfViewConfig entity) {
		if(entity != null) {
			WfViewConfigForm form = new WfViewConfigForm();
			form.setId(entity.getId());
			form.setTemplateId(entity.getTemplateId());
			form.setSelectEntities(entity.getSelectEntities());
			form.setEntitiesJoinClause(entity.getEntitiesJoinClause());
			form.setListProperties(entity.getListProperties());
			form.setQueryProperties(entity.getQueryProperties());
			form.setGroupProperty(entity.getGroupProperty());
			form.setOrderProperty(entity.getOrderProperty());
			form.setOrderby(entity.getOrderby());
			form.setMemo(entity.getMemo());
			form.setWhereClause(entity.getWhereClause());
			form.setKeyProperty(entity.getKeyProperty());
			form.setGroupDir(entity.getGroupDir());
			form.setWhereLogic(entity.getWhereLogic());
			form.setGridColumnWidth(entity.getGridColumnWidth());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(WfViewConfigForm form, WfViewConfig entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			if(form.getTemplateId() != null )
				entity.setTemplateId(form.getTemplateId());
			if(form.getSelectEntities() != null && form.getSelectEntities().trim().length() > 0)
				entity.setSelectEntities(form.getSelectEntities().trim());
			if(form.getEntitiesJoinClause() != null && form.getEntitiesJoinClause().trim().length() > 0)
				entity.setEntitiesJoinClause(form.getEntitiesJoinClause().trim());
			if(form.getListProperties() != null && form.getListProperties().trim().length() > 0)
				entity.setListProperties(form.getListProperties().trim());
			if(form.getQueryProperties() != null && form.getQueryProperties().trim().length() > 0)
				entity.setQueryProperties(form.getQueryProperties().trim());
			if(form.getGroupProperty() != null && form.getGroupProperty().trim().length() > 0)
				entity.setGroupProperty(form.getGroupProperty().trim());
			if(form.getOrderProperty() != null && form.getOrderProperty().trim().length() > 0)
				entity.setOrderProperty(form.getOrderProperty().trim());
			if(form.getOrderby() != null && form.getOrderby().trim().length() > 0)
				entity.setOrderby(form.getOrderby().trim());
			if(form.getMemo() != null && form.getMemo().trim().length() > 0)
				entity.setMemo(form.getMemo().trim());
			if(form.getWhereClause() != null && form.getWhereClause().trim().length() > 0)
				entity.setWhereClause(form.getWhereClause().trim());
			if(form.getKeyProperty() != null && form.getKeyProperty().trim().length() > 0)
				entity.setKeyProperty(form.getKeyProperty().trim());
			if(form.getGroupDir() != null && form.getGroupDir().trim().length()>0){
				entity.setGroupDir(form.getGroupDir().trim());
			}
			if(form.getWhereLogic() != null && form.getWhereLogic().trim().length()>0){
				entity.setWhereLogic(form.getWhereLogic().trim());
			}
			if(form.getGridColumnWidth() != null && form.getGridColumnWidth().trim().length()>0){
				entity.setGridColumnWidth(form.getGridColumnWidth().trim());
			}
		}
	}
	
	public static List<WfViewConfigForm> convertVoListToFormList(List<WfViewConfig> wfViewConfigList) {
		if(wfViewConfigList != null && wfViewConfigList.size() > 0) {
			List<WfViewConfigForm> wfViewConfigFormList = new ArrayList();
			for(int i=0; i<wfViewConfigList.size(); i++) {
				wfViewConfigFormList.add(convertVoToForm(wfViewConfigList.get(i)));
			}
			return wfViewConfigFormList;
		}
		return null;
	}
	
	public static List<WfViewConfig> convertFormListToVoList(List<WfViewConfigForm> wfViewConfigFormList) {
		if(wfViewConfigFormList != null && wfViewConfigFormList.size() > 0) {
			List<WfViewConfig> wfViewConfigList = new ArrayList();
			for(int i=0; i<wfViewConfigFormList.size(); i++) {
				WfViewConfig wfViewConfig = new WfViewConfig();
				convertFormToVo(wfViewConfigFormList.get(i), wfViewConfig);
				wfViewConfigList.add(wfViewConfig);
			}
			return wfViewConfigList;
		}
		return null;
	}
}